package com.aaa.controller;

import com.aaa.entity.Menu;
import com.aaa.entity.Role;
import com.aaa.service.MenuService;
import com.aaa.service.RoleService;
import com.aaa.util.DefaultMsg;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/role")
public class RoleController {
    @Autowired
    private RoleService roleService;
    @Autowired
    private MenuService menuService;
    @RequestMapping("/listAll")
    public PageInfo listAll(String keyword,Integer currentPage, Integer pageSize){
        PageHelper.startPage(currentPage,pageSize);
//        //将数据返回前端
        List<Role> roles = roleService.listAll(keyword);
        PageInfo pageInfo=new PageInfo(roles);
        return pageInfo;
    }

    @RequestMapping("/addOrUpdate")
    public DefaultMsg addOrUpdate(Role role,String menuIds){
        return roleService.addOrUpdate(role, menuIds );
    }
    @RequestMapping("/delete")
    public DefaultMsg delete(Integer rid){
        return roleService.delete(rid);
    }

    @RequestMapping("/listAllMenu")
    public List<Menu> listAll(){
        return menuService.listAll();
    }
}
